<template>
  <div class="add-comment">
    <nav-top title="添加评论" :goback="true"></nav-top>
    <div class="comment-input">
      <span>评论</span>
      <van-field
        class="textarea"
        v-model="comment"
        type="textarea"
        @input="typeComment"
        placeholder="请输入评论(最多两百个字)"
      ></van-field>
    </div>
    <div class="opera">
      <button @click="sub">提交</button>
    </div>
  </div>
</template>

<script>
import NavTop from "@/components/nav/navBar";
import Axios from 'axios';
import { domain } from '../../libs/api_v1';
import { search } from '../../api';
export default {
  components: {
    NavTop
  },
  data() {
    return {
      comment: "",
      ke_jieshao_id:0,
      order:{

      }
    };
  },
  created() {
    
    
  },
  methods: {
    sub() {
      var order_no = search("order_no")
    Axios.get(domain +'/api/order/info?order_no='+order_no)
    .then((res)=>{
      if(res.data.code==1){
        this.order = res.data.data
        Axios.post(domain+'/api/old/pingjia?ke_jieshao_id='+this.order.product_id+'&comment='+this.comment)
        .then((res)=>{
          if(res.data.code==1){
            this.$dialog.alert({ message: "提交成功" })
            .then((res)=>{
              window.location.href="/order"
            })
          }else{
            this.$dialog.alert({ title: res.data.msg, message: res.data.err })
          }
        })
        .catch((err)=>{
          this.$dialog.alert({ title: '提示', message: err })
        })
      }else{
        this.$dialog.alert({ title: res.data.msg, message: res.data.err })
      }
    })
    .catch((err)=>{
      this.$dialog.alert({ title: '提示', message: err })
    })
      
    },
    typeComment() {
      if (this.comment.length > 200) this.comment = this.comment.substring(0, 200);
    }
  }
};
</script>

 <style lang="scss" scoped>
.add-comment {
    margin-top: 50px;
  .comment-input {
    width: 297px;
    height: 160px;
    margin: 0 auto;
    span {
      font-size: 13px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: rgba(33, 33, 33, 1);
      line-height: 30px;
      padding-top: px;
    }
    .textarea {
      padding: 0;
      width: 297px;
      height: 230px;
      background: #f5f5f5;
      textarea {
        ::-webkit-input-placeholder {
          padding: 12px 0 0 11px;
          font-size: 11px;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: rgba(162, 162, 162, 1);
        }
      }
    }
  }
  .opera {
    margin: 180px auto;
    text-align: center;
    button {
      width: 297px;
      height: 41px;
      background: #06a44f;
      border: none;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: rgba(255, 255, 255, 1);
    }
  }
}
</style>
</style>